package procilege.impl.formatter;

import procilege.compute.ExprFormatTraveller;
import procilege.compute.PlaceTypeMetadata;
import procilege.compute.PlaceType;
import procilege.lang.RelationalExpr;

@PlaceTypeMetadata(type = RelationalExpr.class)
public class RelationalExprFormatter implements PlaceType<ExprFormatTraveller> {

	public void visit(ExprFormatTraveller tr, Object place) {

		StringBuilder sb = tr.getBuilder();
		RelationalExpr n = (RelationalExpr) place;

		String op = null;

		switch (n.getRelation()) {
		case RelationalExpr.RELATION_EQ:
			op = "==";
			break;
		case RelationalExpr.RELATION_NEQ:
			op = "!=";
			break;
		case RelationalExpr.RELATION_CATEGORY:
			op = "/=";
			break;
		default:
			throw new UnsupportedOperationException();
		}

		tr.setout(n.getLeft());
		sb.append(op);
		tr.setout(n.getRight());
	}
}